import router from '../router/index.js'
import Router from 'vue-router'
export function formatDate(selectDate,num=2){
  let date=new Date(selectDate);
  let yy=date.getFullYear();
  let mm=(date.getMonth() + 1).toString().padStart(2,'0');
  let dd=(date.getDate()).toString().padStart(2,'0');
  if(num==2){

    return yy+'-'+mm

  }else{
    return yy+'-'+mm+'-'+dd
  }

}

export function addrouteFun(data){
  // 递归添加路由
  let _this=this;
   data.forEach(function(cv, i) {
   let name=cv.path.substring(1,cv.path.length);
    router.addRoute(name, cv);//cv.name
    if (cv.children && cv.children.length) {
      addrouteFun(cv.children)
   }
  })
 
  return data

}

// 时间搓转换
 export function FormatTime(timestamp,type){
	this.timestamp=timestamp;
	this.type=type;
 }
FormatTime.prototype.transferTime=function(){
	let date=new Date(this.timestamp);
	let Y=date.getFullYear();
	let M=(date.getMonth() + 1).toString().padStart(2,'0');
	let D=(date.getDate()).toString().padStart(2,'0');
	let H=(date.getHours()).toString().padStart(2,'0');
	let M2=(date.getMinutes()).toString().padStart(2,'0');
	let S=(date.getSeconds()).toString().padStart(2,'0');
	let obj={
		'Y-M-D/H:M2:S':Y+'-'+M+'-'+D+' '+H+':'+M2+':'+S,//年月日时分秒
		'Y-M-D':Y+'-'+M+'-'+D,//年月日
		'H:M2:S':H+':'+M2+':'+S,//时分秒
		'M-D':M+'-'+D,//月日
	}
	return obj[this.type]
}
